<!DOCTYPE html>

<html
  xmlns="http://www.w3.org/1999/xhtml"
  >
  <head>
    <title>Circular Barplot &#8211; from Data to Viz</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="pandoc" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta
      name="description"
      content="An extensive description of Circular
Barplot. Definition, examples, input data, common caveats, tool to build it and potential alternatives."
    />
    <meta
      name="keywords"
      content="Data,Dataviz,Datavisualization,Plot,Chart,Graph,R,Python,D3,Learning,Caveat,Pitfall,Mistake,Classification"
    />
    <meta name="author" content="Yan Holtz and Conor Healy" />
    <link rel="icon" href="img/logo/data-to-viz.ico" />

    <!-- Control appearance when share by social media -->
    <meta property="og:title" content="Circular Barplot" />
    <meta
      property="og:image"
      content="https://github.com/holtzy/data_to_viz/raw/master/img/section/CircularBarplotSmall.png"
    />
    <meta
      property="og:description"
      content="An extensive description of Circular
Barplot. Definition, examples, input data, common caveats, tool to build it and potential alternatives."
    />
    <meta
      property="og:url"
      content="www.data-to-viz.com/caveat/circularbarplot.html"
    />
    <meta property="og:type" content="website" />

    <style>
      .myheader {
        background-image: url("https://github.com/holtzy/data_to_viz/raw/master/img/overview_RGG_faded.png");
        min-height: 300px;
        background-size: 100% 100%;

        /* Create the parallax scrolling effect */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;

        height: 100%;
        width: 100% !important;
      }
      .mytitle {
        text-transform: uppercase;
        font-family: "Montserrat";
        font-size: 200%;
        font-weight: 500;
        letter-spacing: 4px;
      }
    </style>

    <div class="myheader" style="text-align: center">
      <br />
      <a href="http://www.data-to-viz.com"
        ><img
          align="left"
          src="https://github.com/holtzy/data_to_viz/raw/master/img/logo/typo.png"
          style="width: 150px; vertical-align: top; margin-left: 5%"
      /></a>
      <br /><br />
      <br /><br />
      <a href="http://www.data-to-viz.com">
        <img
          src="https://github.com/holtzy/data_to_viz/raw/master/img/section/CircularBarplotSmall.png"
      /></a>
      <br /><br />
      <p class="mytitle">Circular Barplot</p>
      <p style="color: #d0d0d0">
        <a href="#definition">definition</a> - <a href="#mistake">mistake</a> -
        <a href="#related">related</a> -
        <a href="#code">code</a>
      </p>
    </div>

         <script src="libs/header-attrs-2.27/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/lumen.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
       h1.title {font-size: 38px;}
       h2 {font-size: 30px;}
       h3 {font-size: 24px;}
       h4 {font-size: 18px;}
       h5 {font-size: 16px;}
       h6 {font-size: 12px;}
       code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
       pre:not([class]) { background-color: white }</style>
<script src="libs/navigation-1.1/tabsets.js"></script>
<script src="libs/navigation-1.1/codefolding.js"></script>
<link href="libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
<script src="libs/pagedtable-1.1/js/pagedtable.js"></script>       <style type="text/css">
      code {
        white-space: pre;
      }
    </style>
    <style type="text/css">
      pre > code.sourceCode { white-space: pre; position: relative; }
      pre > code.sourceCode > span { line-height: 1.25; }
      pre > code.sourceCode > span:empty { height: 1.2em; }
      .sourceCode { overflow: visible; }
      code.sourceCode > span { color: inherit; text-decoration: inherit; }
      div.sourceCode { margin: 1em 0; }
      pre.sourceCode { margin: 0; }
      @media screen {
      div.sourceCode { overflow: auto; }
      }
      @media print {
      pre > code.sourceCode { white-space: pre-wrap; }
      pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
      }
      pre.numberSource code
        { counter-reset: source-line 0; }
      pre.numberSource code > span
        { position: relative; left: -4em; counter-increment: source-line; }
      pre.numberSource code > span > a:first-child::before
        { content: counter(source-line);
          position: relative; left: -1em; text-align: right; vertical-align: baseline;
          border: none; display: inline-block;
          -webkit-touch-callout: none; -webkit-user-select: none;
          -khtml-user-select: none; -moz-user-select: none;
          -ms-user-select: none; user-select: none;
          padding: 0 4px; width: 4em;
          color: #aaaaaa;
        }
      pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
      div.sourceCode
        {   }
      @media screen {
      pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
      }
      code span.al { color: #ff0000; font-weight: bold; } /* Alert */
      code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
      code span.at { color: #7d9029; } /* Attribute */
      code span.bn { color: #40a070; } /* BaseN */
      code span.bu { color: #008000; } /* BuiltIn */
      code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
      code span.ch { color: #4070a0; } /* Char */
      code span.cn { color: #880000; } /* Constant */
      code span.co { color: #60a0b0; font-style: italic; } /* Comment */
      code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
      code span.do { color: #ba2121; font-style: italic; } /* Documentation */
      code span.dt { color: #902000; } /* DataType */
      code span.dv { color: #40a070; } /* DecVal */
      code span.er { color: #ff0000; font-weight: bold; } /* Error */
      code span.ex { } /* Extension */
      code span.fl { color: #40a070; } /* Float */
      code span.fu { color: #06287e; } /* Function */
      code span.im { color: #008000; font-weight: bold; } /* Import */
      code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
      code span.kw { color: #007020; font-weight: bold; } /* Keyword */
      code span.op { color: #666666; } /* Operator */
      code span.ot { color: #007020; } /* Other */
      code span.pp { color: #bc7a00; } /* Preprocessor */
      code span.sc { color: #4070a0; } /* SpecialChar */
      code span.ss { color: #bb6688; } /* SpecialString */
      code span.st { color: #4070a0; } /* String */
      code span.va { color: #19177c; } /* Variable */
      code span.vs { color: #4070a0; } /* VerbatimString */
      code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
            div.sourceCode {
        overflow-x: visible;
      }
          </style>
        <style type="text/css">
      pre:not([class]) {
        background-color: white;
      }
    </style>
           <style type="text/css">
      h1 {
        font-size: 34px;
      }
      h1.title {
        font-size: 38px;
      }
      h2 {
        font-size: 30px;
      }
      h3 {
        font-size: 24px;
      }
      h4 {
        font-size: 18px;
      }
      h5 {
        font-size: 16px;
      }
      h6 {
        font-size: 12px;
      }
      .table th:not([align]) {
        text-align: left;
      }
          </style>
         <link
      rel="stylesheet"
      href="style.css"
      type="text/css"
      
    />
      </head>

  <body>
        <style type="text/css">
      .main-container {
        max-width: 940px;
        margin-left: auto;
        margin-right: auto;
      }
      code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
      }
      img {
        max-width: 100%;
        height: auto;
      }
      .tabbed-pane {
        padding-top: 12px;
      }
      button.code-folding-btn:focus {
        outline: none;
      }
    </style>

     
    <div class="container-fluid main-container">
      <!-- tabsets -->
      <script>
        $(document).ready(function () {
          window.buildTabsets("TOC");
        });
      </script>

      <!-- code folding -->
            <style type="text/css">
        .code-folding-btn {
          margin-bottom: 4px;
        }
      </style>
      <script>
        $(document).ready(function () {
                          window.initializeCodeFolding("hide" === "show");
                });
      </script>
         
                    <div class="fluid-row" id="header">
                        <div class="btn-group pull-right">
              <button
                type="button"
                class="btn btn-default btn-xs dropdown-toggle"
                data-toggle="dropdown"
                aria-haspopup="true"
                aria-expanded="false"
              >
                <span>Show Code</span> <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" style="min-width: 50px">
                                <li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
                <li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
                                </ul>
            </div>

                         </div>

              <div class="mycontent">
<div id="definition" class="section level1">
<h1>Definition</h1>
<hr />
<p>A <code>circular barplot</code> is a <a
href="https://www.data-to-viz.com/graph/barplot">barplot</a>, with each
bar displayed along a circle instead of a line. Thus, it is advised to
have a good understanding of how barplot works before making it
circular. Circular bar chart is very ‘eye catching’ and allows a better
use of the space than a long usual barplot.</p>
<p><br></p>
<p>Here is an example showing the quantity of weapons exported by the
top 20 largest exporters in 2017 (more info <a
href="http://www.data-to-viz.com/story/OneNumOneCat.html">here</a>):</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="co"># Libraries</span></span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="fu">library</span>(hrbrthemes)</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="fu">library</span>(kableExtra)</span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a><span class="fu">options</span>(<span class="at">knitr.table.format =</span> <span class="st">&quot;html&quot;</span>)</span>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a><span class="fu">library</span>(viridis)</span>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a></span>
<span id="cb1-8"><a href="#cb1-8" tabindex="-1"></a><span class="co"># Load dataset from github</span></span>
<span id="cb1-9"><a href="#cb1-9" tabindex="-1"></a>data <span class="ot">&lt;-</span> <span class="fu">read.table</span>(<span class="st">&quot;https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum.csv&quot;</span>, <span class="at">header=</span><span class="cn">TRUE</span>, <span class="at">sep=</span><span class="st">&quot;,&quot;</span>)</span>
<span id="cb1-10"><a href="#cb1-10" tabindex="-1"></a></span>
<span id="cb1-11"><a href="#cb1-11" tabindex="-1"></a><span class="co"># Order data</span></span>
<span id="cb1-12"><a href="#cb1-12" tabindex="-1"></a>tmp <span class="ot">&lt;-</span> data <span class="sc">%&gt;%</span></span>
<span id="cb1-13"><a href="#cb1-13" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Value)) <span class="sc">%&gt;%</span></span>
<span id="cb1-14"><a href="#cb1-14" tabindex="-1"></a>  <span class="fu">arrange</span>(<span class="fu">desc</span>(Value)) <span class="sc">%&gt;%</span></span>
<span id="cb1-15"><a href="#cb1-15" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Country=</span><span class="fu">factor</span>(Country, Country))</span>
<span id="cb1-16"><a href="#cb1-16" tabindex="-1"></a></span>
<span id="cb1-17"><a href="#cb1-17" tabindex="-1"></a><span class="co"># Set a number of &#39;empty bar&#39;</span></span>
<span id="cb1-18"><a href="#cb1-18" tabindex="-1"></a>empty_bar<span class="ot">=</span><span class="dv">10</span></span>
<span id="cb1-19"><a href="#cb1-19" tabindex="-1"></a></span>
<span id="cb1-20"><a href="#cb1-20" tabindex="-1"></a><span class="co"># Add lines to the initial tmpset</span></span>
<span id="cb1-21"><a href="#cb1-21" tabindex="-1"></a>to_add <span class="ot">=</span> <span class="fu">matrix</span>(<span class="cn">NA</span>, empty_bar, <span class="fu">ncol</span>(tmp))</span>
<span id="cb1-22"><a href="#cb1-22" tabindex="-1"></a><span class="fu">colnames</span>(to_add) <span class="ot">=</span> <span class="fu">colnames</span>(tmp)</span>
<span id="cb1-23"><a href="#cb1-23" tabindex="-1"></a>tmp<span class="ot">=</span><span class="fu">rbind</span>(tmp, to_add)</span>
<span id="cb1-24"><a href="#cb1-24" tabindex="-1"></a>tmp<span class="sc">$</span>id<span class="ot">=</span><span class="fu">seq</span>(<span class="dv">1</span>, <span class="fu">nrow</span>(tmp))</span>
<span id="cb1-25"><a href="#cb1-25" tabindex="-1"></a></span>
<span id="cb1-26"><a href="#cb1-26" tabindex="-1"></a><span class="co"># Get the name and the y position of each label</span></span>
<span id="cb1-27"><a href="#cb1-27" tabindex="-1"></a>label_tmp<span class="ot">=</span>tmp</span>
<span id="cb1-28"><a href="#cb1-28" tabindex="-1"></a>number_of_bar<span class="ot">=</span><span class="fu">nrow</span>(label_tmp)</span>
<span id="cb1-29"><a href="#cb1-29" tabindex="-1"></a>angle<span class="ot">=</span> <span class="dv">90</span> <span class="sc">-</span> <span class="dv">360</span> <span class="sc">*</span> (label_tmp<span class="sc">$</span>id<span class="fl">-0.5</span>) <span class="sc">/</span>number_of_bar     <span class="co"># I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)</span></span>
<span id="cb1-30"><a href="#cb1-30" tabindex="-1"></a>label_tmp<span class="sc">$</span>hjust<span class="ot">&lt;-</span><span class="fu">ifelse</span>( angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, <span class="dv">1</span>, <span class="dv">0</span>)</span>
<span id="cb1-31"><a href="#cb1-31" tabindex="-1"></a>label_tmp<span class="sc">$</span>angle<span class="ot">&lt;-</span><span class="fu">ifelse</span>(angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, angle<span class="sc">+</span><span class="dv">180</span>, angle)</span>
<span id="cb1-32"><a href="#cb1-32" tabindex="-1"></a>label_tmp<span class="sc">$</span>Country <span class="ot">&lt;-</span> <span class="fu">gsub</span>(<span class="st">&quot;United States&quot;</span>, <span class="st">&quot;US&quot;</span>, label_tmp<span class="sc">$</span>Country)</span>
<span id="cb1-33"><a href="#cb1-33" tabindex="-1"></a>label_tmp<span class="sc">$</span>Country <span class="ot">&lt;-</span> <span class="fu">paste</span>(label_tmp<span class="sc">$</span>Country, <span class="st">&quot; (&quot;</span>, label_tmp<span class="sc">$</span>Value,<span class="st">&quot;)&quot;</span>, <span class="at">sep=</span><span class="st">&quot;&quot;</span>)</span>
<span id="cb1-34"><a href="#cb1-34" tabindex="-1"></a></span>
<span id="cb1-35"><a href="#cb1-35" tabindex="-1"></a><span class="co"># Make the plot</span></span>
<span id="cb1-36"><a href="#cb1-36" tabindex="-1"></a><span class="fu">ggplot</span>(tmp, <span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>Value)) <span class="sc">+</span>       <span class="co"># Note that id is a factor. If x is numeric, there is some space between the first bar</span></span>
<span id="cb1-37"><a href="#cb1-37" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">stat=</span><span class="st">&quot;identity&quot;</span>, <span class="at">fill=</span><span class="fu">alpha</span>(<span class="st">&quot;#69b3a2&quot;</span>, <span class="fl">0.8</span>)) <span class="sc">+</span></span>
<span id="cb1-38"><a href="#cb1-38" tabindex="-1"></a>  <span class="fu">ylim</span>(<span class="sc">-</span><span class="dv">7000</span>,<span class="dv">13000</span>) <span class="sc">+</span></span>
<span id="cb1-39"><a href="#cb1-39" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb1-40"><a href="#cb1-40" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb1-41"><a href="#cb1-41" tabindex="-1"></a>    <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb1-42"><a href="#cb1-42" tabindex="-1"></a>    <span class="at">axis.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb1-43"><a href="#cb1-43" tabindex="-1"></a>    <span class="at">panel.grid =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb1-44"><a href="#cb1-44" tabindex="-1"></a>    <span class="at">plot.margin =</span> <span class="fu">unit</span>(<span class="fu">rep</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>) </span>
<span id="cb1-45"><a href="#cb1-45" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb1-46"><a href="#cb1-46" tabindex="-1"></a>  <span class="fu">coord_polar</span>(<span class="at">start =</span> <span class="dv">0</span>) <span class="sc">+</span> </span>
<span id="cb1-47"><a href="#cb1-47" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>label_tmp, <span class="fu">aes</span>(<span class="at">x=</span>id, <span class="at">y=</span>Value<span class="sc">+</span><span class="dv">200</span>, <span class="at">label=</span>Country ), <span class="at">color=</span><span class="st">&quot;black&quot;</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>,<span class="at">alpha=</span><span class="fl">0.6</span>, <span class="at">size=</span><span class="fl">2.5</span>, <span class="at">angle=</span> label_tmp<span class="sc">$</span>angle, <span class="at">hjust=</span>label_tmp<span class="sc">$</span>hjust, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb1-48"><a href="#cb1-48" tabindex="-1"></a>  <span class="fu">geom_text</span>( <span class="fu">aes</span>(<span class="at">x=</span><span class="dv">24</span>, <span class="at">y=</span><span class="dv">8000</span>, <span class="at">label=</span><span class="st">&quot;Who sells more weapons?&quot;</span>), <span class="at">color=</span><span class="st">&quot;black&quot;</span>, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
<p><img src="circularbarplot_files/figure-html/unnamed-chunk-1-1.png" width="672" style="display: block; margin: auto;" /></p>
<p><em>Note</em>:</p>
<ul>
<li>Here no Y scale is displayed since exact values are written on each
bar.</li>
<li>More representation of this dataset are available <a
href="http://www.data-to-viz.com/story/OneNumOneCat.html">here</a>, with
further explanation.</li>
</ul>
</div>
<div id="what-for" class="section level1">
<h1>What for</h1>
<hr />
<p>Circular barplot is really eye catching but makes it more difficult
to read the differences between each bar size. Thus, circular barcharts
make sense only if you have a huge number of bar to display, and if an
obvious pattern pops out.</p>
<p><br></p>
<p>In my opinion, circular barplot gets even more interesting with a
grouping variable. In the following example that uses dummy data, it is
easy to compare groups and entities into each group.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="co"># Create dataset</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">data.frame</span>(</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a>  <span class="at">individual=</span><span class="fu">paste</span>( <span class="st">&quot;Mister &quot;</span>, <span class="fu">seq</span>(<span class="dv">1</span>,<span class="dv">60</span>), <span class="at">sep=</span><span class="st">&quot;&quot;</span>),</span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a>  <span class="at">group=</span><span class="fu">c</span>( <span class="fu">rep</span>(<span class="st">&#39;A&#39;</span>, <span class="dv">10</span>), <span class="fu">rep</span>(<span class="st">&#39;B&#39;</span>, <span class="dv">30</span>), <span class="fu">rep</span>(<span class="st">&#39;C&#39;</span>, <span class="dv">14</span>), <span class="fu">rep</span>(<span class="st">&#39;D&#39;</span>, <span class="dv">6</span>)) ,</span>
<span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a>  <span class="at">value=</span><span class="fu">sample</span>( <span class="fu">seq</span>(<span class="dv">10</span>,<span class="dv">100</span>), <span class="dv">60</span>, <span class="at">replace=</span>T)</span>
<span id="cb2-6"><a href="#cb2-6" tabindex="-1"></a>)</span>
<span id="cb2-7"><a href="#cb2-7" tabindex="-1"></a>data <span class="ot">=</span> data <span class="sc">%&gt;%</span> <span class="fu">arrange</span>(group, value)</span>
<span id="cb2-8"><a href="#cb2-8" tabindex="-1"></a></span>
<span id="cb2-9"><a href="#cb2-9" tabindex="-1"></a><span class="co"># Set a number of &#39;empty bar&#39; to add at the end of each group</span></span>
<span id="cb2-10"><a href="#cb2-10" tabindex="-1"></a>empty_bar<span class="ot">=</span><span class="dv">3</span></span>
<span id="cb2-11"><a href="#cb2-11" tabindex="-1"></a>to_add <span class="ot">=</span> <span class="fu">data.frame</span>( <span class="fu">matrix</span>(<span class="cn">NA</span>, empty_bar<span class="sc">*</span><span class="fu">nlevels</span>(data<span class="sc">$</span>group), <span class="fu">ncol</span>(data)) )</span>
<span id="cb2-12"><a href="#cb2-12" tabindex="-1"></a><span class="fu">colnames</span>(to_add) <span class="ot">=</span> <span class="fu">colnames</span>(data)</span>
<span id="cb2-13"><a href="#cb2-13" tabindex="-1"></a>to_add<span class="sc">$</span>group<span class="ot">=</span><span class="fu">rep</span>(<span class="fu">levels</span>(data<span class="sc">$</span>group), <span class="at">each=</span>empty_bar)</span>
<span id="cb2-14"><a href="#cb2-14" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">rbind</span>(data, to_add)</span>
<span id="cb2-15"><a href="#cb2-15" tabindex="-1"></a>data<span class="ot">=</span>data <span class="sc">%&gt;%</span> <span class="fu">arrange</span>(group)</span>
<span id="cb2-16"><a href="#cb2-16" tabindex="-1"></a>data<span class="sc">$</span>id<span class="ot">=</span><span class="fu">seq</span>(<span class="dv">1</span>, <span class="fu">nrow</span>(data))</span>
<span id="cb2-17"><a href="#cb2-17" tabindex="-1"></a> </span>
<span id="cb2-18"><a href="#cb2-18" tabindex="-1"></a><span class="co"># Get the name and the y position of each label</span></span>
<span id="cb2-19"><a href="#cb2-19" tabindex="-1"></a>label_data<span class="ot">=</span>data</span>
<span id="cb2-20"><a href="#cb2-20" tabindex="-1"></a>number_of_bar<span class="ot">=</span><span class="fu">nrow</span>(label_data)</span>
<span id="cb2-21"><a href="#cb2-21" tabindex="-1"></a>angle<span class="ot">=</span> <span class="dv">90</span> <span class="sc">-</span> <span class="dv">360</span> <span class="sc">*</span> (label_data<span class="sc">$</span>id<span class="fl">-0.5</span>) <span class="sc">/</span>number_of_bar     <span class="co"># I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)</span></span>
<span id="cb2-22"><a href="#cb2-22" tabindex="-1"></a>label_data<span class="sc">$</span>hjust<span class="ot">&lt;-</span><span class="fu">ifelse</span>( angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, <span class="dv">1</span>, <span class="dv">0</span>)</span>
<span id="cb2-23"><a href="#cb2-23" tabindex="-1"></a>label_data<span class="sc">$</span>angle<span class="ot">&lt;-</span><span class="fu">ifelse</span>(angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, angle<span class="sc">+</span><span class="dv">180</span>, angle)</span>
<span id="cb2-24"><a href="#cb2-24" tabindex="-1"></a> </span>
<span id="cb2-25"><a href="#cb2-25" tabindex="-1"></a><span class="co"># prepare a data frame for base lines</span></span>
<span id="cb2-26"><a href="#cb2-26" tabindex="-1"></a>base_data<span class="ot">=</span>data <span class="sc">%&gt;%</span> </span>
<span id="cb2-27"><a href="#cb2-27" tabindex="-1"></a>  <span class="fu">group_by</span>(group) <span class="sc">%&gt;%</span> </span>
<span id="cb2-28"><a href="#cb2-28" tabindex="-1"></a>  <span class="fu">summarize</span>(<span class="at">start=</span><span class="fu">min</span>(id), <span class="at">end=</span><span class="fu">max</span>(id) <span class="sc">-</span> empty_bar) <span class="sc">%&gt;%</span> </span>
<span id="cb2-29"><a href="#cb2-29" tabindex="-1"></a>  <span class="fu">rowwise</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb2-30"><a href="#cb2-30" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">title=</span><span class="fu">mean</span>(<span class="fu">c</span>(start, end)))</span>
<span id="cb2-31"><a href="#cb2-31" tabindex="-1"></a> </span>
<span id="cb2-32"><a href="#cb2-32" tabindex="-1"></a><span class="co"># prepare a data frame for grid (scales)</span></span>
<span id="cb2-33"><a href="#cb2-33" tabindex="-1"></a>grid_data <span class="ot">=</span> base_data</span>
<span id="cb2-34"><a href="#cb2-34" tabindex="-1"></a>grid_data<span class="sc">$</span>end <span class="ot">=</span> grid_data<span class="sc">$</span>end[ <span class="fu">c</span>( <span class="fu">nrow</span>(grid_data), <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(grid_data)<span class="sc">-</span><span class="dv">1</span>)] <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb2-35"><a href="#cb2-35" tabindex="-1"></a>grid_data<span class="sc">$</span>start <span class="ot">=</span> grid_data<span class="sc">$</span>start <span class="sc">-</span> <span class="dv">1</span></span>
<span id="cb2-36"><a href="#cb2-36" tabindex="-1"></a>grid_data<span class="ot">=</span>grid_data[<span class="sc">-</span><span class="dv">1</span>,]</span>
<span id="cb2-37"><a href="#cb2-37" tabindex="-1"></a> </span>
<span id="cb2-38"><a href="#cb2-38" tabindex="-1"></a><span class="co"># Make the plot</span></span>
<span id="cb2-39"><a href="#cb2-39" tabindex="-1"></a>p <span class="ot">=</span> <span class="fu">ggplot</span>(data, <span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>group)) <span class="sc">+</span>       <span class="co"># Note that id is a factor. If x is numeric, there is some space between the first bar</span></span>
<span id="cb2-40"><a href="#cb2-40" tabindex="-1"></a>  </span>
<span id="cb2-41"><a href="#cb2-41" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>group), <span class="at">stat=</span><span class="st">&quot;identity&quot;</span>, <span class="at">alpha=</span><span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb2-42"><a href="#cb2-42" tabindex="-1"></a>  </span>
<span id="cb2-43"><a href="#cb2-43" tabindex="-1"></a>  <span class="co"># Add a val=100/75/50/25 lines. I do it at the beginning to make sur barplots are OVER it.</span></span>
<span id="cb2-44"><a href="#cb2-44" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">80</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">80</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb2-45"><a href="#cb2-45" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">60</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">60</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb2-46"><a href="#cb2-46" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">40</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">40</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb2-47"><a href="#cb2-47" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">20</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">20</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb2-48"><a href="#cb2-48" tabindex="-1"></a>  </span>
<span id="cb2-49"><a href="#cb2-49" tabindex="-1"></a>  <span class="co"># Add text showing the value of each 100/75/50/25 lines</span></span>
<span id="cb2-50"><a href="#cb2-50" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">&quot;text&quot;</span>, <span class="at">x =</span> <span class="fu">rep</span>(<span class="fu">max</span>(data<span class="sc">$</span>id),<span class="dv">4</span>), <span class="at">y =</span> <span class="fu">c</span>(<span class="dv">20</span>, <span class="dv">40</span>, <span class="dv">60</span>, <span class="dv">80</span>), <span class="at">label =</span> <span class="fu">c</span>(<span class="st">&quot;20&quot;</span>, <span class="st">&quot;40&quot;</span>, <span class="st">&quot;60&quot;</span>, <span class="st">&quot;80&quot;</span>) , <span class="at">color=</span><span class="st">&quot;grey&quot;</span>, <span class="at">size=</span><span class="dv">3</span> , <span class="at">angle=</span><span class="dv">0</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>, <span class="at">hjust=</span><span class="dv">1</span>) <span class="sc">+</span></span>
<span id="cb2-51"><a href="#cb2-51" tabindex="-1"></a>  </span>
<span id="cb2-52"><a href="#cb2-52" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>group), <span class="at">stat=</span><span class="st">&quot;identity&quot;</span>, <span class="at">alpha=</span><span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb2-53"><a href="#cb2-53" tabindex="-1"></a>  <span class="fu">ylim</span>(<span class="sc">-</span><span class="dv">100</span>,<span class="dv">120</span>) <span class="sc">+</span></span>
<span id="cb2-54"><a href="#cb2-54" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb2-55"><a href="#cb2-55" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb2-56"><a href="#cb2-56" tabindex="-1"></a>    <span class="at">legend.position =</span> <span class="st">&quot;none&quot;</span>,</span>
<span id="cb2-57"><a href="#cb2-57" tabindex="-1"></a>    <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb2-58"><a href="#cb2-58" tabindex="-1"></a>    <span class="at">axis.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb2-59"><a href="#cb2-59" tabindex="-1"></a>    <span class="at">panel.grid =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb2-60"><a href="#cb2-60" tabindex="-1"></a>    <span class="at">plot.margin =</span> <span class="fu">unit</span>(<span class="fu">rep</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>) </span>
<span id="cb2-61"><a href="#cb2-61" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb2-62"><a href="#cb2-62" tabindex="-1"></a>  <span class="fu">coord_polar</span>() <span class="sc">+</span> </span>
<span id="cb2-63"><a href="#cb2-63" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>label_data, <span class="fu">aes</span>(<span class="at">x=</span>id, <span class="at">y=</span>value<span class="sc">+</span><span class="dv">10</span>, <span class="at">label=</span>individual, <span class="at">hjust=</span>hjust), <span class="at">color=</span><span class="st">&quot;black&quot;</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>,<span class="at">alpha=</span><span class="fl">0.6</span>, <span class="at">size=</span><span class="fl">2.5</span>, <span class="at">angle=</span> label_data<span class="sc">$</span>angle, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb2-64"><a href="#cb2-64" tabindex="-1"></a>  </span>
<span id="cb2-65"><a href="#cb2-65" tabindex="-1"></a>  <span class="co"># Add base line information</span></span>
<span id="cb2-66"><a href="#cb2-66" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>base_data, <span class="fu">aes</span>(<span class="at">x =</span> start, <span class="at">y =</span> <span class="sc">-</span><span class="dv">5</span>, <span class="at">xend =</span> end, <span class="at">yend =</span> <span class="sc">-</span><span class="dv">5</span>), <span class="at">colour =</span> <span class="st">&quot;black&quot;</span>, <span class="at">alpha=</span><span class="fl">0.8</span>, <span class="at">size=</span><span class="fl">0.6</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> )  <span class="sc">+</span></span>
<span id="cb2-67"><a href="#cb2-67" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>base_data, <span class="fu">aes</span>(<span class="at">x =</span> title, <span class="at">y =</span> <span class="sc">-</span><span class="dv">18</span>, <span class="at">label=</span>group), <span class="at">hjust=</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">0</span>,<span class="dv">0</span>), <span class="at">colour =</span> <span class="st">&quot;black&quot;</span>, <span class="at">alpha=</span><span class="fl">0.8</span>, <span class="at">size=</span><span class="dv">4</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span>)</span>
<span id="cb2-68"><a href="#cb2-68" tabindex="-1"></a> </span>
<span id="cb2-69"><a href="#cb2-69" tabindex="-1"></a>p</span></code></pre></div>
<p><img src="circularbarplot_files/figure-html/unnamed-chunk-2-1.png" width="768" style="display: block; margin: auto;" /></p>
</div>
<div id="variation" class="section level1">
<h1>Variation</h1>
<hr />
<p>Most of the variations presented for the <a
href="https://www.data-to-viz.com/graph/barplot">barplot</a> are
obviously available for the circular barplot. For instance, you can
group your variable and stack the group to get a
<code>stacked circular barplot</code>:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="co"># Create dataset</span></span>
<span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">data.frame</span>(</span>
<span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a>  <span class="at">individual=</span><span class="fu">paste</span>( <span class="st">&quot;Mister &quot;</span>, <span class="fu">seq</span>(<span class="dv">1</span>,<span class="dv">60</span>), <span class="at">sep=</span><span class="st">&quot;&quot;</span>),</span>
<span id="cb3-4"><a href="#cb3-4" tabindex="-1"></a>  <span class="at">group=</span><span class="fu">c</span>( <span class="fu">rep</span>(<span class="st">&#39;A&#39;</span>, <span class="dv">10</span>), <span class="fu">rep</span>(<span class="st">&#39;B&#39;</span>, <span class="dv">30</span>), <span class="fu">rep</span>(<span class="st">&#39;C&#39;</span>, <span class="dv">14</span>), <span class="fu">rep</span>(<span class="st">&#39;D&#39;</span>, <span class="dv">6</span>)) ,</span>
<span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a>  <span class="at">value1=</span><span class="fu">sample</span>( <span class="fu">seq</span>(<span class="dv">10</span>,<span class="dv">100</span>), <span class="dv">60</span>, <span class="at">replace=</span>T),</span>
<span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a>  <span class="at">value2=</span><span class="fu">sample</span>( <span class="fu">seq</span>(<span class="dv">10</span>,<span class="dv">100</span>), <span class="dv">60</span>, <span class="at">replace=</span>T),</span>
<span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a>  <span class="at">value3=</span><span class="fu">sample</span>( <span class="fu">seq</span>(<span class="dv">10</span>,<span class="dv">100</span>), <span class="dv">60</span>, <span class="at">replace=</span>T)</span>
<span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a>)</span>
<span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a> </span>
<span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a><span class="co"># Transform data in a tidy format (long format)</span></span>
<span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a>data <span class="ot">=</span> data <span class="sc">%&gt;%</span> <span class="fu">gather</span>(<span class="at">key =</span> <span class="st">&quot;observation&quot;</span>, <span class="at">value=</span><span class="st">&quot;value&quot;</span>, <span class="sc">-</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>)) </span>
<span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a> </span>
<span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a><span class="co"># Set a number of &#39;empty bar&#39; to add at the end of each group</span></span>
<span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a>empty_bar<span class="ot">=</span><span class="dv">2</span></span>
<span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a>nObsType<span class="ot">=</span><span class="fu">nlevels</span>(<span class="fu">as.factor</span>(data<span class="sc">$</span>observation))</span>
<span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a>to_add <span class="ot">=</span> <span class="fu">data.frame</span>( <span class="fu">matrix</span>(<span class="cn">NA</span>, empty_bar<span class="sc">*</span><span class="fu">nlevels</span>(data<span class="sc">$</span>group)<span class="sc">*</span>nObsType, <span class="fu">ncol</span>(data)) )</span>
<span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a><span class="fu">colnames</span>(to_add) <span class="ot">=</span> <span class="fu">colnames</span>(data)</span>
<span id="cb3-18"><a href="#cb3-18" tabindex="-1"></a>to_add<span class="sc">$</span>group<span class="ot">=</span><span class="fu">rep</span>(<span class="fu">levels</span>(data<span class="sc">$</span>group), <span class="at">each=</span>empty_bar<span class="sc">*</span>nObsType )</span>
<span id="cb3-19"><a href="#cb3-19" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">rbind</span>(data, to_add)</span>
<span id="cb3-20"><a href="#cb3-20" tabindex="-1"></a>data<span class="ot">=</span>data <span class="sc">%&gt;%</span> <span class="fu">arrange</span>(group, individual)</span>
<span id="cb3-21"><a href="#cb3-21" tabindex="-1"></a>data<span class="sc">$</span>id<span class="ot">=</span><span class="fu">rep</span>( <span class="fu">seq</span>(<span class="dv">1</span>, <span class="fu">nrow</span>(data)<span class="sc">/</span>nObsType) , <span class="at">each=</span>nObsType)</span>
<span id="cb3-22"><a href="#cb3-22" tabindex="-1"></a> </span>
<span id="cb3-23"><a href="#cb3-23" tabindex="-1"></a><span class="co"># Get the name and the y position of each label</span></span>
<span id="cb3-24"><a href="#cb3-24" tabindex="-1"></a>label_data<span class="ot">=</span> data <span class="sc">%&gt;%</span> <span class="fu">group_by</span>(id, individual) <span class="sc">%&gt;%</span> <span class="fu">summarize</span>(<span class="at">tot=</span><span class="fu">sum</span>(value))</span>
<span id="cb3-25"><a href="#cb3-25" tabindex="-1"></a>number_of_bar<span class="ot">=</span><span class="fu">nrow</span>(label_data)</span>
<span id="cb3-26"><a href="#cb3-26" tabindex="-1"></a>angle<span class="ot">=</span> <span class="dv">90</span> <span class="sc">-</span> <span class="dv">360</span> <span class="sc">*</span> (label_data<span class="sc">$</span>id<span class="fl">-0.5</span>) <span class="sc">/</span>number_of_bar     <span class="co"># I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)</span></span>
<span id="cb3-27"><a href="#cb3-27" tabindex="-1"></a>label_data<span class="sc">$</span>hjust<span class="ot">&lt;-</span><span class="fu">ifelse</span>( angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, <span class="dv">1</span>, <span class="dv">0</span>)</span>
<span id="cb3-28"><a href="#cb3-28" tabindex="-1"></a>label_data<span class="sc">$</span>angle<span class="ot">&lt;-</span><span class="fu">ifelse</span>(angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, angle<span class="sc">+</span><span class="dv">180</span>, angle)</span>
<span id="cb3-29"><a href="#cb3-29" tabindex="-1"></a> </span>
<span id="cb3-30"><a href="#cb3-30" tabindex="-1"></a><span class="co"># prepare a data frame for base lines</span></span>
<span id="cb3-31"><a href="#cb3-31" tabindex="-1"></a>base_data<span class="ot">=</span>data <span class="sc">%&gt;%</span> </span>
<span id="cb3-32"><a href="#cb3-32" tabindex="-1"></a>  <span class="fu">group_by</span>(group) <span class="sc">%&gt;%</span> </span>
<span id="cb3-33"><a href="#cb3-33" tabindex="-1"></a>  <span class="fu">summarize</span>(<span class="at">start=</span><span class="fu">min</span>(id), <span class="at">end=</span><span class="fu">max</span>(id) <span class="sc">-</span> empty_bar) <span class="sc">%&gt;%</span> </span>
<span id="cb3-34"><a href="#cb3-34" tabindex="-1"></a>  <span class="fu">rowwise</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb3-35"><a href="#cb3-35" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">title=</span><span class="fu">mean</span>(<span class="fu">c</span>(start, end)))</span>
<span id="cb3-36"><a href="#cb3-36" tabindex="-1"></a> </span>
<span id="cb3-37"><a href="#cb3-37" tabindex="-1"></a><span class="co"># prepare a data frame for grid (scales)</span></span>
<span id="cb3-38"><a href="#cb3-38" tabindex="-1"></a>grid_data <span class="ot">=</span> base_data</span>
<span id="cb3-39"><a href="#cb3-39" tabindex="-1"></a>grid_data<span class="sc">$</span>end <span class="ot">=</span> grid_data<span class="sc">$</span>end[ <span class="fu">c</span>( <span class="fu">nrow</span>(grid_data), <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(grid_data)<span class="sc">-</span><span class="dv">1</span>)] <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb3-40"><a href="#cb3-40" tabindex="-1"></a>grid_data<span class="sc">$</span>start <span class="ot">=</span> grid_data<span class="sc">$</span>start <span class="sc">-</span> <span class="dv">1</span></span>
<span id="cb3-41"><a href="#cb3-41" tabindex="-1"></a>grid_data<span class="ot">=</span>grid_data[<span class="sc">-</span><span class="dv">1</span>,]</span>
<span id="cb3-42"><a href="#cb3-42" tabindex="-1"></a> </span>
<span id="cb3-43"><a href="#cb3-43" tabindex="-1"></a><span class="co"># Make the plot</span></span>
<span id="cb3-44"><a href="#cb3-44" tabindex="-1"></a>p <span class="ot">=</span> <span class="fu">ggplot</span>(data) <span class="sc">+</span>      </span>
<span id="cb3-45"><a href="#cb3-45" tabindex="-1"></a>  </span>
<span id="cb3-46"><a href="#cb3-46" tabindex="-1"></a>  <span class="co"># Add the stacked bar</span></span>
<span id="cb3-47"><a href="#cb3-47" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>observation), <span class="at">stat=</span><span class="st">&quot;identity&quot;</span>, <span class="at">alpha=</span><span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb3-48"><a href="#cb3-48" tabindex="-1"></a>  <span class="fu">scale_fill_viridis</span>(<span class="at">discrete=</span><span class="cn">TRUE</span>) <span class="sc">+</span></span>
<span id="cb3-49"><a href="#cb3-49" tabindex="-1"></a>  </span>
<span id="cb3-50"><a href="#cb3-50" tabindex="-1"></a>  <span class="co"># Add a val=100/75/50/25 lines. I do it at the beginning to make sur barplots are OVER it.</span></span>
<span id="cb3-51"><a href="#cb3-51" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">0</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">0</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-52"><a href="#cb3-52" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">50</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">50</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-53"><a href="#cb3-53" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">100</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">100</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-54"><a href="#cb3-54" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">150</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">150</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-55"><a href="#cb3-55" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>grid_data, <span class="fu">aes</span>(<span class="at">x =</span> end, <span class="at">y =</span> <span class="dv">200</span>, <span class="at">xend =</span> start, <span class="at">yend =</span> <span class="dv">200</span>), <span class="at">colour =</span> <span class="st">&quot;grey&quot;</span>, <span class="at">alpha=</span><span class="dv">1</span>, <span class="at">size=</span><span class="fl">0.3</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-56"><a href="#cb3-56" tabindex="-1"></a>  </span>
<span id="cb3-57"><a href="#cb3-57" tabindex="-1"></a>  <span class="co"># Add text showing the value of each 100/75/50/25 lines</span></span>
<span id="cb3-58"><a href="#cb3-58" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">&quot;text&quot;</span>, <span class="at">x =</span> <span class="fu">rep</span>(<span class="fu">max</span>(data<span class="sc">$</span>id),<span class="dv">5</span>), <span class="at">y =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">50</span>, <span class="dv">100</span>, <span class="dv">150</span>, <span class="dv">200</span>), <span class="at">label =</span> <span class="fu">c</span>(<span class="st">&quot;0&quot;</span>, <span class="st">&quot;50&quot;</span>, <span class="st">&quot;100&quot;</span>, <span class="st">&quot;150&quot;</span>, <span class="st">&quot;200&quot;</span>) , <span class="at">color=</span><span class="st">&quot;grey&quot;</span>, <span class="at">size=</span><span class="dv">2</span> , <span class="at">angle=</span><span class="dv">0</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>, <span class="at">hjust=</span><span class="dv">1</span>) <span class="sc">+</span></span>
<span id="cb3-59"><a href="#cb3-59" tabindex="-1"></a>  </span>
<span id="cb3-60"><a href="#cb3-60" tabindex="-1"></a>  <span class="fu">ylim</span>(<span class="sc">-</span><span class="dv">150</span>,<span class="fu">max</span>(label_data<span class="sc">$</span>tot, <span class="at">na.rm=</span>T)) <span class="sc">+</span></span>
<span id="cb3-61"><a href="#cb3-61" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb3-62"><a href="#cb3-62" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb3-63"><a href="#cb3-63" tabindex="-1"></a>    <span class="at">legend.position =</span> <span class="st">&quot;none&quot;</span>,</span>
<span id="cb3-64"><a href="#cb3-64" tabindex="-1"></a>    <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb3-65"><a href="#cb3-65" tabindex="-1"></a>    <span class="at">axis.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb3-66"><a href="#cb3-66" tabindex="-1"></a>    <span class="at">panel.grid =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb3-67"><a href="#cb3-67" tabindex="-1"></a>    <span class="at">plot.margin =</span> <span class="fu">unit</span>(<span class="fu">rep</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>) </span>
<span id="cb3-68"><a href="#cb3-68" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb3-69"><a href="#cb3-69" tabindex="-1"></a>  <span class="fu">coord_polar</span>() <span class="sc">+</span></span>
<span id="cb3-70"><a href="#cb3-70" tabindex="-1"></a>  </span>
<span id="cb3-71"><a href="#cb3-71" tabindex="-1"></a>  <span class="co"># Add labels on top of each bar</span></span>
<span id="cb3-72"><a href="#cb3-72" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>label_data, <span class="fu">aes</span>(<span class="at">x=</span>id, <span class="at">y=</span>tot<span class="sc">+</span><span class="dv">10</span>, <span class="at">label=</span>individual, <span class="at">hjust=</span>hjust), <span class="at">color=</span><span class="st">&quot;black&quot;</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>,<span class="at">alpha=</span><span class="fl">0.6</span>, <span class="at">size=</span><span class="dv">1</span>, <span class="at">angle=</span> label_data<span class="sc">$</span>angle, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) <span class="sc">+</span></span>
<span id="cb3-73"><a href="#cb3-73" tabindex="-1"></a>  </span>
<span id="cb3-74"><a href="#cb3-74" tabindex="-1"></a>  <span class="co"># Add base line information</span></span>
<span id="cb3-75"><a href="#cb3-75" tabindex="-1"></a>  <span class="fu">geom_segment</span>(<span class="at">data=</span>base_data, <span class="fu">aes</span>(<span class="at">x =</span> start, <span class="at">y =</span> <span class="sc">-</span><span class="dv">5</span>, <span class="at">xend =</span> end, <span class="at">yend =</span> <span class="sc">-</span><span class="dv">5</span>), <span class="at">colour =</span> <span class="st">&quot;black&quot;</span>, <span class="at">alpha=</span><span class="fl">0.8</span>, <span class="at">size=</span><span class="fl">0.6</span> , <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> )  <span class="sc">+</span></span>
<span id="cb3-76"><a href="#cb3-76" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>base_data, <span class="fu">aes</span>(<span class="at">x =</span> title, <span class="at">y =</span> <span class="sc">-</span><span class="dv">18</span>, <span class="at">label=</span>group), <span class="at">hjust=</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">0</span>,<span class="dv">0</span>), <span class="at">colour =</span> <span class="st">&quot;black&quot;</span>, <span class="at">alpha=</span><span class="fl">0.8</span>, <span class="at">size=</span><span class="dv">4</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span>)</span>
<span id="cb3-77"><a href="#cb3-77" tabindex="-1"></a>p</span></code></pre></div>
<p><img src="circularbarplot_files/figure-html/unnamed-chunk-3-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="mistake" class="section level1">
<h1>Common mistakes</h1>
<hr />
<ul>
<li>The proportion of the <a
href="https://www.data-to-viz.com/caveat/circular_bar_yaxis.html">inner
circle must be huge</a> (&gt;1/2). Otherwise bars are very skewed like
on the next example. In my opinion this distorts reality: biggest bars
look even bigger that they are. You can read more about that in the <a
href="https://www.data-to-viz.com/caveat/circular_bar_yaxis.html">dedicated
article</a>.</li>
</ul>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="co"># Create dataset</span></span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">data.frame</span>(</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a>  <span class="at">individual=</span><span class="fu">paste</span>( <span class="st">&quot;Mister &quot;</span>, <span class="fu">seq</span>(<span class="dv">1</span>,<span class="dv">30</span>), <span class="at">sep=</span><span class="st">&quot;&quot;</span>),</span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a>  <span class="at">group=</span><span class="fu">c</span>( <span class="fu">rep</span>(<span class="st">&#39;A&#39;</span>, <span class="dv">10</span>), <span class="fu">rep</span>(<span class="st">&#39;C&#39;</span>, <span class="dv">14</span>), <span class="fu">rep</span>(<span class="st">&#39;D&#39;</span>, <span class="dv">6</span>)) ,</span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a>  <span class="at">value=</span><span class="fu">sample</span>( <span class="fu">seq</span>(<span class="dv">10</span>,<span class="dv">100</span>), <span class="dv">30</span>, <span class="at">replace=</span>T)</span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a>)</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a>data <span class="ot">=</span> data <span class="sc">%&gt;%</span> <span class="fu">arrange</span>(group, value)</span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a></span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a><span class="co"># Set a number of &#39;empty bar&#39; to add at the end of each group</span></span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a>empty_bar<span class="ot">=</span><span class="dv">1</span></span>
<span id="cb4-11"><a href="#cb4-11" tabindex="-1"></a>to_add <span class="ot">=</span> <span class="fu">data.frame</span>( <span class="fu">matrix</span>(<span class="cn">NA</span>, empty_bar<span class="sc">*</span><span class="fu">nlevels</span>(data<span class="sc">$</span>group), <span class="fu">ncol</span>(data)) )</span>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a><span class="fu">colnames</span>(to_add) <span class="ot">=</span> <span class="fu">colnames</span>(data)</span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a>to_add<span class="sc">$</span>group<span class="ot">=</span><span class="fu">rep</span>(<span class="fu">levels</span>(data<span class="sc">$</span>group), <span class="at">each=</span>empty_bar)</span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a>data<span class="ot">=</span><span class="fu">rbind</span>(data, to_add)</span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a>data<span class="ot">=</span>data <span class="sc">%&gt;%</span> <span class="fu">arrange</span>(group)</span>
<span id="cb4-16"><a href="#cb4-16" tabindex="-1"></a>data<span class="sc">$</span>id<span class="ot">=</span><span class="fu">seq</span>(<span class="dv">1</span>, <span class="fu">nrow</span>(data))</span>
<span id="cb4-17"><a href="#cb4-17" tabindex="-1"></a> </span>
<span id="cb4-18"><a href="#cb4-18" tabindex="-1"></a><span class="co"># Get the name and the y position of each label</span></span>
<span id="cb4-19"><a href="#cb4-19" tabindex="-1"></a>label_data<span class="ot">=</span>data</span>
<span id="cb4-20"><a href="#cb4-20" tabindex="-1"></a>number_of_bar<span class="ot">=</span><span class="fu">nrow</span>(label_data)</span>
<span id="cb4-21"><a href="#cb4-21" tabindex="-1"></a>angle<span class="ot">=</span> <span class="dv">90</span> <span class="sc">-</span> <span class="dv">360</span> <span class="sc">*</span> (label_data<span class="sc">$</span>id<span class="fl">-0.5</span>) <span class="sc">/</span>number_of_bar     <span class="co"># I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)</span></span>
<span id="cb4-22"><a href="#cb4-22" tabindex="-1"></a>label_data<span class="sc">$</span>hjust<span class="ot">&lt;-</span><span class="fu">ifelse</span>( angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, <span class="dv">1</span>, <span class="dv">0</span>)</span>
<span id="cb4-23"><a href="#cb4-23" tabindex="-1"></a>label_data<span class="sc">$</span>angle<span class="ot">&lt;-</span><span class="fu">ifelse</span>(angle <span class="sc">&lt;</span> <span class="sc">-</span><span class="dv">90</span>, angle<span class="sc">+</span><span class="dv">180</span>, angle)</span>
<span id="cb4-24"><a href="#cb4-24" tabindex="-1"></a> </span>
<span id="cb4-25"><a href="#cb4-25" tabindex="-1"></a></span>
<span id="cb4-26"><a href="#cb4-26" tabindex="-1"></a><span class="co"># Make the plot</span></span>
<span id="cb4-27"><a href="#cb4-27" tabindex="-1"></a>p <span class="ot">=</span> <span class="fu">ggplot</span>(data, <span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>group)) <span class="sc">+</span>       <span class="co"># Note that id is a factor. If x is numeric, there is some space between the first bar</span></span>
<span id="cb4-28"><a href="#cb4-28" tabindex="-1"></a>  </span>
<span id="cb4-29"><a href="#cb4-29" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="fu">aes</span>(<span class="at">x=</span><span class="fu">as.factor</span>(id), <span class="at">y=</span>value, <span class="at">fill=</span>group), <span class="at">stat=</span><span class="st">&quot;identity&quot;</span>, <span class="at">alpha=</span><span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb4-30"><a href="#cb4-30" tabindex="-1"></a>  <span class="fu">ylim</span>(<span class="sc">-</span><span class="dv">10</span>,<span class="dv">120</span>) <span class="sc">+</span></span>
<span id="cb4-31"><a href="#cb4-31" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb4-32"><a href="#cb4-32" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb4-33"><a href="#cb4-33" tabindex="-1"></a>    <span class="at">legend.position =</span> <span class="st">&quot;none&quot;</span>,</span>
<span id="cb4-34"><a href="#cb4-34" tabindex="-1"></a>    <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb4-35"><a href="#cb4-35" tabindex="-1"></a>    <span class="at">axis.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb4-36"><a href="#cb4-36" tabindex="-1"></a>    <span class="at">panel.grid =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb4-37"><a href="#cb4-37" tabindex="-1"></a>    <span class="at">plot.margin =</span> <span class="fu">unit</span>(<span class="fu">rep</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>) </span>
<span id="cb4-38"><a href="#cb4-38" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb4-39"><a href="#cb4-39" tabindex="-1"></a>  <span class="fu">coord_polar</span>() <span class="sc">+</span> </span>
<span id="cb4-40"><a href="#cb4-40" tabindex="-1"></a>  <span class="fu">geom_text</span>(<span class="at">data=</span>label_data, <span class="fu">aes</span>(<span class="at">x=</span>id, <span class="at">y=</span>value<span class="sc">+</span><span class="dv">10</span>, <span class="at">label=</span>individual, <span class="at">hjust=</span>hjust), <span class="at">color=</span><span class="st">&quot;black&quot;</span>, <span class="at">fontface=</span><span class="st">&quot;bold&quot;</span>,<span class="at">alpha=</span><span class="fl">0.6</span>, <span class="at">size=</span><span class="fl">2.5</span>, <span class="at">angle=</span> label_data<span class="sc">$</span>angle, <span class="at">inherit.aes =</span> <span class="cn">FALSE</span> ) </span>
<span id="cb4-41"><a href="#cb4-41" tabindex="-1"></a>  </span>
<span id="cb4-42"><a href="#cb4-42" tabindex="-1"></a>p</span></code></pre></div>
<p><img src="circularbarplot_files/figure-html/unnamed-chunk-4-1.png" width="768" style="display: block; margin: auto;" /></p>
<ul>
<li>Works only if you have many levels to display (&gt; ~40) and a clear
pattern</li>
<li>Keep displaying a Y axis all along the circle.</li>
<li><a href="http://www.data-to-viz.com/caveat/order_data.html">Order
your bars</a>. If the levels of your categoric variable have no obvious
order, order the bars following their values.</li>
<li>Several values per group? <a
href="http://www.data-to-viz.com/caveat/error_bar.html">Don’t use a
barplot</a>. Even with error bars, it hides information and other type
of graphic like <a
href="https://www.data-to-viz.com/caveat/boxplot.html">boxplot</a> or <a
href="https://www.data-to-viz.com/graph/violin.html">violin</a> are much
more appropriate.</li>
</ul>
</div>
<div id="related" class="section level1">
<h1>Related</h1>
<hr />
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="http://www.data-to-viz.com/graph/barplot.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/BarSmall.png">
<p class="mytitlerelated">
Barplot
</p>
<p class="mytextrelated">
Represents the value of entities using bar of various length.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="http://www.data-to-viz.com/graph/lollipop.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/LollipopSmall.png">
<p class="mytitlerelated">
Lollipop plot
</p>
<p class="mytextrelated">
A fancy barplot where bars are replaced with a dot and a segment. Allows
even more options when it comes to stacking.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="http://www.data-to-viz.com/caveat/spider.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/SpiderSmall.png">
<p class="mytitlerelated">
Spider / Radar
</p>
<p class="mytextrelated">
One or more series of values over multiple common quantitative
variables. Axis are joint on the middle of the figure.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="http://www.data-to-viz.com/graph/wordcloud.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/WordCloudSmall.png">
<p class="mytitlerelated">
Wordcloud
</p>
<p class="mytextrelated">
A visual representation of text data, where word size is relative to
their frequency.
</p>
</a>
</div>
</div>
</div>
<div id="code" class="section level1">
<h1>Build your own</h1>
<hr />
<p>The <a
href="https://r-graph-gallery.com/circular-barplot.html">R</a>, <a
href="https:/python-graph-gallery.com/circular-barplot/">Python</a>, <a
href="https://www.react-graph-gallery.com/circular-barplot">React</a>
and <a href="https://d3-graph-gallery.com/circular_barplot.html">D3</a>
graph galleries are 4 websites providing hundreds of chart example,
always providing the reproducible code. Click the button below to see
how to build the chart you need with your favorite programing
language.</p>
<p>
<a href="https://r-graph-gallery.com/circular-barplot.html" class="btn btn-primary">R
graph gallery</a>
<a href="https://python-graph-gallery.com/circular-barplot/" class="btn btn-primary">Python
gallery</a>
<a href="https://www.react-graph-gallery.com/circular-barplot" class="btn btn-primary">React
gallery</a>
<a href="https://d3-graph-gallery.com/circular_barplot.html" class="btn btn-primary">D3
gallery</a>
</p>
</div>
</div>

          <section
            id="form"
            style="
              margin-top: 70px;
              padding-bottom: 70px;
              padding-top: 70px;
              background-color: #f8f9fa;
            "
          >
            <div class="container">
              <div
                style="
                  display: flex;
                  flex-direction: column;
                  align-items: center;
                "
              >
                <h2 style="font-size: 44px" class="text-center">
                  Dataviz decision tree
                </h2>
                <p
                  class="text-center"
                  style="max-width: 600px; font-size: 18px"
                >
                  <a href="https://www.data-to-viz.com">Data To Viz</a> is a
                  comprehensive <b>classification of chart types</b> organized
                  by data input format. Get a high-resolution version of our
                  decision tree delivered to your inbox now!
                </p>
                <div
                  style="
                    margin-top: -50px;
                    width: 100%;
                    display: flex;
                    justify-content: center;
                  "
                >
                  <script
                    async
                    data-uid="8010f15fd2"
                    src="https://prodigious-trailblazer-3628.ck.page/8010f15fd2/index.js"
                  ></script>
                </div>
                <br />
                <div class="text-center">
                  <img
                    class="img-fluid"
                    src="../img/poster/poster_small.png"
                    alt="High Resolution Poster"
                    style="max-width: 400px"
                  />
                </div>
              </div>
            </div>
          </section>

           &nbsp;
<hr />
<p style="text-align: center;">A work by <a href="https://www.yan-holtz.com/">Yan Holtz</a> for <a href="https://data-to-viz.com">data-to-viz.com</a></p>

<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Add font awesome icons -->
<p style="text-align: center;">
	<a href="https://twitter.com/r_graph_gallery?lang=en" class="fa fa-twitter"></a>
	<a href="https://www.linkedin.com/in/yan-holtz-2477534a/" class="fa fa-linkedin"></a>
	<a href="https://github.com/holtzy/" class="fa fa-github"></a>
</p>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-3"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-79254642-3');
</script>
<script>
var getOutboundLink = function(url) {
	gtag('event', 'click', {
		'event_category': 'outbound',
		'event_label': url,
		'transport_type': 'beacon',
		'event_callback': function(){document.location = url;}
	});
}
</script>

&nbsp;                </div>

    <script>

      // add bootstrap table styles to pandoc tables
      function bootstrapStylePandocTables() {
        $('tr.header').parent('thead').parent('table').addClass('table table-condensed');
      }
      $(document).ready(function () {
        bootstrapStylePandocTables();
      });

          </script>
       </body>
</html>
